package enhanced.neural.network.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import enhanced.neural.network.dao.UserMapper;
import lombok.extern.slf4j.Slf4j;
import enhanced.neural.network.dto.UserInfo;
import enhanced.neural.network.pojo.UserInfoDO;
import enhanced.neural.network.service.UserService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class UserServiceImpl implements UserService {

    private final UserMapper userMapper;

    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    /**
     * @return
     */
    @Override
    public List<UserInfo> queryUserList() {
        QueryWrapper<UserInfoDO> queryWrapper = new QueryWrapper<>();

        List<UserInfoDO> userInfoDOS = userMapper.selectList(queryWrapper);
        log.info("查询到的用户信息是：{}", JSONUtil.toJsonStr(userInfoDOS));
        return userInfoDOS.stream().map(userInfoDO -> {
            UserInfo userInfo = new UserInfo();
            BeanUtil.copyProperties(userInfoDO, userInfo);
//            userInfo.setCreateTime(DateUtil.formatDateTime(userInfoDO.getCreateTime()));
//            userInfo.setModifyTime(DateUtil.formatDateTime(userInfoDO.getModifyTime()));
            return userInfo;
        }).collect(Collectors.toList());
    }

    /**
     * @param list
     */
    @Override
    public void insert(List<UserInfo> list) {
        for (UserInfo userInfo : list) {
            UserInfoDO userInfoDO = new UserInfoDO();
            BeanUtil.copyProperties(userInfo, userInfoDO);
            userMapper.insert(userInfoDO);
        }
    }
}
